<?php
	// The global MediaWiki cache is disabled
	global $wgMainCacheType;
	global $wgMessageCacheType;
	global $wgParserCacheType;
	global $wgCachePages;

	$wgMainCacheType = CACHE_NONE;
	$wgMessageCacheType = CACHE_NONE;
	$wgParserCacheType = CACHE_NONE;
	$wgCachePages = false;

	global $wgUseAjax;
	$wgUseAjax = true;
	$wgAjaxExportList[] = 'registerGlobalFlagST';
	$wgAjaxExportList[] = 'getParametersOfTransclusion';

	// If there is no instance created of MediaWiki, end the program
	if( !defined ( 'MEDIAWIKI' ) ) {
		echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
		die( -1 );
	}

	// The classes are registered
	$wgAutoloadClasses [ 'MediaWikiExtension' ] = '/MediaWikiExtension.body.php';
	$wgAutoloadClasses [ 'MediaWikiExtensionParser' ] = '/MediaWikiExtension.hooks.php';

	// Credits
	$wgExtensionCredits [ 'other' ][] = array(
	    'path'         	=> 	'extensions/MediaWikiExtension/MediaWikiExtension.body.php',
		'name'         	=> 	'Unique ID Transclusion Extension for MediaWiki',
		'version'      	=> 	'0.0.1',
		'author'       	=> 	'Jaime Penagos',
		'url'         	=> 	'http://www.mediawiki.org/wiki/Manual:Tag_extensions',
		'description'  	=> 	'Description of the extension'
	);

	$wgExtensionCredits [ 'parserhook' ][] = array(
		'path'         	=> 	'extensions/MediaWikiExtension/MediaWikiExtension.hooks.php',
		'name' 			=> 	"Parser function for Unique ID Transclusion Extension",
		'version' 		=> 	'0.0.1',
		'author' 		=> 	"Jaime Penagos",
		'url' 			=> 	"http://www.mediawiki.org/w/index.php?title=Manual:Parser_functions",
		'description' 	=>	'Description of the parsing extension'
		// TODO: Should be using descriptionmsg instead so that i18n is supported (but this is a simple example).
	);

	// The necessary files are included
	require_once( __DIR__ . "/MediaWikiExtension.hooks.php" );
	require_once( __DIR__ . "/MediaWikiExtension.body.php" );
	require_once( __DIR__ . "/include/php/TransclusionManagerDAO.php" );

	// The database is initialized.
	$transclusionSingleton = TransclusionDAO::singleton();
	$transclusionSingleton -> initTransclusionDB();

	session_start();

	// Start the session variables
	if(!isset( $_SESSION['trTSourceArticle'] ) ){
		$_SESSION['trTSourceArticle'] = '[source]';
	}

	if(!isset( $_SESSION['trTTargetArticle'] ) ){
		$_SESSION['trTTargetArticle'] = '[target]';
	}

	function registerGlobalFlagST($tipo, $flagStatus, $urlArticulo){
		$resultado = '';

		if ( $tipo == 'source' ){
			if ( $flagStatus == "true" ){
				$_SESSION['trTSourceArticle'] = $urlArticulo;
				$resultado = ' [SET]';

			}
			else{
				$_SESSION['trTSourceArticle'] = "[source]";
				$resultado = ' [UNSET]';
			}
		}

		if ( $tipo == 'target' ){
			if ( $flagStatus == "true" ){
				$_SESSION['trTTargetArticle'] = $urlArticulo;
				$resultado = ' [SET]';
			}
			else{
				$_SESSION['trTTargetArticle'] = "[target]";
				$resultado = ' [UNSET]';
			}
		}
		return $resultado;
	}

	function getParametersOfTransclusion(){
		$resultado = "trTarget=" . $_SESSION['trTTargetArticle'] . "&trSource=" . $_SESSION['trTSourceArticle'];

		registerGlobalFlagST("source","false","");
		registerGlobalFlagST("source","false","");

		return $resultado;
	}
?>